﻿using System;

namespace MathService.DSP.Signals
{
    [Serializable]
    public partial class PeriodicDigitalSignal : DigitalSignal, ICloneable
    {
        /* -------------------------------------------------------------------------------------------- */

    	/* -------------------------------------------------------------------------------------------- */

    	public double Period { get; private set; }

    	public override double this[double t]
        {
            get { return base[t % Period]; }
            set { base[t % Period] = value; }
        }

        public override double this[int n]
        {
            get { return base[n % SamplesCount]; }
            set { base[n % SamplesCount] = value; }
        }

        /* -------------------------------------------------------------------------------------------- */

        public PeriodicDigitalSignal(double dx, double Period)
            : base(dx, Period) { }

        public PeriodicDigitalSignal(DigitalSignal PeriodOfSignal)
            : base(PeriodOfSignal)
        {
            Period = Length;
        }

        public PeriodicDigitalSignal(PeriodicDigitalSignal Signal)
            : base(Signal)
        {
            Period = Signal.Period;
        }

        /* -------------------------------------------------------------------------------------------- */

        #region ICloneable Members

        object ICloneable.Clone()
        {
            return new PeriodicDigitalSignal(this);
        }

        #endregion

        /* -------------------------------------------------------------------------------------------- */
    }
}
